モジュール:DiaM
local p = {} local chrome = require("Dev:Colors") local colData = mw.loadData( 'Module:Code/col' ) local ucData = mw.loadData( 'Module:Code/uc' ) local jpData = mw.loadData( 'Module:Code/jp' ) local enData = mw.loadData( 'Module:Code/en' ) local emData = mw.loadData('Module:Code/emote') -- ユニークカラー時の名前制御用 local args = {} -- Arguments passed to template local dia -- Actual dia local twow = {} ------------------------------------------------ -- ARGUMENTS PREPROCESSOR -- * データロードしながら値を定めます ------------------------------------------------ --- Preprocessor for the arguments. -- Will fill up the args table with the parameters from the frame grouped by their type. -- -- @param frame The frame passed to the Module. local function preProcessArgs(frame) local tmp = {} if frame mw.getCurrentFrame() then tmp = frame:getParent().args else tmp = frame end -- Loop over all the args for k,v in pairs(tmp) do -- Skip empty args, which are useless if v ~= '' then local cat,num = tostring(k):match('^(%a+)(1-9%d*)$') argsk = v -- Simple copy end end local id = args'id' twow'icnm' = id twow'text' = args'text' twow'name' = emDataid or id twow'col' = ucDataid or colDatatwow.name or {255, 255, 255} end ------------------------------------------------ -- processColor/色を定めます ------------------------------------------------ local function prgb(fa) return chrome.fromRgb(fa1 or 255, fa2 or 255, fa3 or 255, 0.58) end local function processColor() local diastyle = 'border:7px solid '..prgb(twow.col):hex()..'; background-color:'..prgb(twow.col):hex()..';' if args.bodyclass then dia:addClass(args.bodyclass) end dia:cssText(diastyle) if args.bodystyle then dia:cssText( args.bodystyle ) end end local function processColor2() local newcol = prgb(twow.col):rotate(180); return 'color:'..newcol:lighten(-75):alpha(100):hex()..'; background-color:'..newcol:lighten(75):hex()..';' end ------------------------------------------------ -- processName/名前欄です ------------------------------------------------ --- processIcon/アイコンを置きます local function icExist(name) local ict = mw.title.new(name) if ict nil then return false end return ict.exists end local function processIcon(row) local iconcell = mw.html.create('td'):attr('rowspan',2):addClass('dia-image') local image = 'File:Dia'..(twow.icnm or 'ZZUnknown')..'.png' local icexist = icExist(image) local iclink = '' if twow.icnm ~= 'ZZUnknown' then iclink = twow.name end if not icexist then image = 'File:DiaZZUnknown.png' end local width = args.iconwidth or '80px' if iclink ~= nil then iconcell:wikitext('['..'image ..'|'.. width ..'|link='.. iclink ..''..']') else iconcell:wikitext('['..'image ..'|'.. width ..'|link='..']') end if args.iconclass then iconcell:addClass( args.iconclass ) end if args.iconstyle then iconcell:cssText( args.iconstyle ) end row:node(iconcell) end --- 名前欄はアイコンと同じ段です local function processName() local namerow = mw.html.create('tr') local namecell = mw.html.create('th'):addClass('dia-name'):attr('valign','top') local namestyle2 = processColor2() local jname = jpDatatwow.name or '' twow.name = enDatatwow.name or twow.name processIcon(namerow) if args'name' ~= nil then namecell:wikitext(args.name) elseif jname ~= nil then namecell:wikitext(jname..'('..(twow.name or '???')..')') else namecell:wikitext(twow.name or '???') end if args.nameclass then namecell:addClass( args.nameclass ) end namecell:cssText(namestyle2) if args.namestyle then namecell:cssText( args.namestyle ) end namerow:node(namecell) dia:node(namerow) end ------------------------------------------------ -- processText/テキストを入力します ------------------------------------------------ local function processText() local textrow = mw.html.create('tr'):addClass('dia-text') local textcell = mw.html.create('th'):attr('valign','top') if twow.name nil then textcell:wikitext('※nameの値が不正です') end if twow.icnm nil then textcell:wikitext('※idの値が不正です') end if twow.col nil then textcell:wikitext('※colの値が不正です') end textcell:wikitext(twow.text) if args.textclass then textrow:addClass( args.textclass ) end if args.textstyle then textcell:cssText( args.textstyle ) end textrow:node(textcell) dia:node(textrow) end ------------------------------------------------ -- MAIN FUNCTIONS ------------------------------------------------ --- Processes the arguments to create the dialog. -- -- @return A string with HTML that is the dialog. local function _dia() -- Create the root HTML element local trim = function(s) return s and mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") or '' end local border = args.border or trim(args1) or '' dia = mw.html.create('table'):addClass('dia') -- Process... processColor() processName() processText() return tostring(dia) end --- Main module entry point. -- To be called with or directly from another module. -- -- @param frame The frame passed to the module via the #invoke. If called from another -- module directly, this should be a table with the parameter definition. function p.main(frame) -- データロードも忘れずに preProcessArgs(frame) return _dia() end return p -- Category:Modules